<?php
namespace Tool;

class Tool{

    /**
     * 字符串加密函数，用于MD5加密
     * @param $str string 要加密的字符串
     * @param int $num     要加密的次数
     * @return string 返回加密后的字符串
     */
    public static function password($str,$num=3)
    {
        for ($i = 0; $i < $num; $i++)
        {
            $str = md5($str);
        }
        return $str;
    }

    /**
     * HTTP GET 操作
     * @param $url
     * @return mixed
     */
    public static function get($url)
    {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HEADER,0);
        $results = curl_exec($ch);
        return $results;
    }

    /**
     * HTTP POST 操作
     * @param $url
     * @return mixed
     */
    public static function post($url)
    {
        $data = http_build_query($_POST);
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_POST,true);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        $results = curl_exec($ch);
        curl_close($ch);
        return $results;
    }

}
